<%@ page contentType="text/html; charset=utf-8" language="java"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<%@include file="/static/common/header.jsp"%>
<%@include file="/static/common/easyui.jsp"%>
<%@include file="/static/common/common.jsp"%>
<link href="${ctx}/static/css/main.css" rel="stylesheet">
<html>
<head>
<script language="javascript">
function setButtonLink(){
	if(document.referrer==""){
		self.close();
	}else{
		history.back(-1);
	}
	
} 
function closeWindow() {
	parent.closeWindow();
}
function refreshFrame(opt) {
	parent.refreshFrame(opt);
}
function refreshData(opt) {
	parent.refreshData(opt);
}
$(function() {
<c:if test="${execJS!=null}">
${execJS}
</c:if>
});
function backToUrl(url){
	window.location.href = '${ctx}'+url;
}

function showNotice() {
	if ($("#sms_flag").attr("checked")) {//选中  
		$("#smsTd").css("display", "");
		$("#mobileTd").css("display", "");
		$("#mobileTd1").css("display", "none");
	} else {
		$("#smsTd").css("display", "none");
		$("#mobileTd").css("display", "none");
		$("#mobileTd1").css("display", "");
	}

	if ($("#email_flag").attr("checked")) {//选中  
		$("#emailTd").css("display", "");
		$("#contentTd").css("display", "");
		$("#contentTd1").css("display", "none");
	} else {
		$("#emailTd").css("display", "none");
		$("#contentTd").css("display", "none");
		$("#contentTd1").css("display", "");
	}
}

function dealOrder() {
	//消息推送校验
	var smsFlag = "N";
	var emailFlag = "N";
	if ($("#sms_flag").attr("checked")) {//选中  
		smsFlag = "Y";
	}
	if ($("#email_flag").attr("checked")) {//选中  
		emailFlag = "Y";
	}
	
	var mobileNo = $("#mobileNo").val();
	var emailAdd = $("#emailAdd").val();
	var smsContent = $("#smsContent").val();
	var emailContent = $("#emailContent").val();
	
	if(smsFlag=='Y') {
		if(validateMobile(mobileNo)) {
			if (smsContent == null || smsContent == '') {
				$.messager.alert('提示', "短信通知内容为空", 'info');
				return false;
			}
		} else {
			return false;
		}
	}
	
	if(emailFlag=='Y') {
		if(validateEmail(emailAdd)) {
			if (emailContent == null || emailContent == '') {
				$.messager.alert('提示', "邮件通知内容为空", 'info');
				return false;
			}
		} else {
			return false;
		}
	}
	
	var custId = $("#custId").val();
	var orderId = $("#orderId").val();
	
	//校验完成
	var data = {
		//客户信息
		custId: custId,
		orderId: orderId,
		smsFlag: smsFlag,
		emailFlag: emailFlag,
		mobileNo: mobileNo,
		emailAdd: emailAdd,
		smsContent: smsContent,
		emailContent: emailContent
	};
	
	$.postJSON("${ctx}/infobird/call/saveNotice", data, function(data) {
		if (data && data.success == "true") {
			$.messager.alert('提示', '保存成功', 'info');
			closeWindow();
		} else {
			$.messager.alert('提示', data.err_msg, 'info');
		}
	});
	
}
</script>
</head>
<body style="overflow: hidden">
	<form id="dealResultForm" name="dealResultForm" method="post" >
		<!-- 隐藏域 -->
		<input type="hidden" id="mobile" name="mobile" value="${cust.mobile}">
		<input type="hidden" id="email" name="email" value="${cust.email}">
		<input type="hidden" id="orderId" name="orderId" value="${order.id}">
		<input type="hidden" id="custId" name="custId" value="${cust.id}">
	
			<!-- 短信&邮件通知 -->
			<table class="listTable" style="width: 100%">
				<tr>
					<th width="140px" height="50px" rowspan="2" >
						<input type="checkbox" id="sms_flag" name="sms_flag" onclick="showNotice();"/>
						短信通知：
					</th>
					<td id="mobileTd1" style="display: block" rowspan="2">
					</td>
					<td id="mobileTd" style="display: none">
						手机号码：
						<input type="text" id="mobileNo" name="mobileNo" value="${cust.mobile}">
					</td>
				</tr>
				<tr>
					<td id="smsTd" height="50px" style="display: none">
						<textarea rows="3" cols="120" name="smsContent" id="smsContent"></textarea>
					</td>
				</tr>
				<tr>
					<th width="140px" height="50px" rowspan="2">
						<input type="checkbox" id="email_flag" name="email_flag" onclick="showNotice();" />
						邮件通知：
					</th>
					<td id="contentTd1" style="display: block" rowspan="2">
					</td>
					<td id="contentTd" style="display: none">
						邮件地址：
						<input type="text" id="emailAdd" name="emailAdd" value="${cust.email}" >
					</td>
				</tr>
				<tr>
					<td id="emailTd" height="50px" style="display: none">
						<textarea rows="3" cols="120" name="emailContent" id="emailContent"></textarea>
					</td>
				</tr>
			</table>
				
				<div style="text-align:center;padding:5px;margin-top:5px;margin-bottom:5px;">
					<a href="javascript:void(0);" id="btn-add" onclick="dealOrder();" class="easyui-linkbutton" iconCls="icon-ok">保存提交工单</a>
				</div>	
	</form>
</body>
</html>